
package com.kugou.game.sdk.protocol;

import com.kugou.framework.base.LogUtil;
import com.kugou.framework.http.ResponsePackage;
import com.kugou.game.sdk.entity.ResponseMessage;

/**
 * 描述:请求响应包基类
 *
 * @author jerryliu
 * @since 2015年10月26日 下午12:44:12
 * @param <T>
 */
public abstract class HttpBaseResponsePackage<T extends ResponseMessage> implements
        ResponsePackage<T> {

    private byte[] mData;

    @Override
    public void setContext(byte[] data) {
        mData = data;
    }

    @Override
    public void getResponseData(T t) {
        if (mData != null && mData.length > 0) {
            String jsonStr = "";
            try {
                jsonStr = new String(mData, "utf-8");
                handleResponse(t, jsonStr);
            } catch (Exception e) {
                LogUtil.d("response", "error_source:" + jsonStr);
                e.printStackTrace();
            }
        } else {
            LogUtil.d("response", "no response content");
        }
    }

    /**
     * 处理响应结果json
     * 
     * @param response 解析数据封装的对象
     * @param responseJsonStr 响应数据json字符串
     */
    protected abstract void handleResponse(T response, String responseJsonStr);

}
